/**
 * 
 */
package info.niwota.commons;

import org.json.JSONException;
import org.json.JSONObject;

/**
 * @author qiangli
 * 
 */
public class FileItem {
	public long date;
	public String name;
	public String path;
	public long size;
	public String type;
	public boolean isFile = false;

	public FileItem() {
	}

	public FileItem(String name) {
		this.name = name;
	}

	public FileItem(String name, String path) {
		this.name = name;
		this.path = path;
	}

	public FileItem(String name, String path, long date, long size,
			String type) {
		this.name = name;
		this.path = path;
		this.date = date;
		this.size = size;
		this.type = type;
	}

	public JSONObject toJSONObject() {
		JSONObject jo = new JSONObject();
		try {
			jo.put("date", date);
			jo.put("name", name);
			jo.put("path", path);
			jo.put("size", size);
			jo.put("type", type);
			jo.put("isFile", isFile);
		} catch (Exception e) {
			try {
				jo.put("error", e.getLocalizedMessage());
			} catch (JSONException e1) {
				e1.printStackTrace();
			}
		}
		return jo;
	}
	
	@Override
	public String toString() {
		return toJSONObject().toString();
	}
}
